package cn.antblog.thread;

import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author yangjy
 * @version 1.0
 * @description: TODO
 * @date 2022/4/11 16:56
 */
public class ScheduledThreadPool {


    public static void main(String[] args) {
        ScheduledExecutorService scheduleService = new ScheduledThreadPoolExecutor(10);
        scheduleService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("time1 = " + new Date());
            }
        }, 0, 60, TimeUnit.SECONDS);
        scheduleService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("time2 = " + new Date());
            }
        }, 10, 60, TimeUnit.SECONDS);
        scheduleService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("time3 = " + new Date());
            }
        }, 40, 60, TimeUnit.SECONDS);
        scheduleService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("time4 = " + new Date());
            }
        }, 50, 60, TimeUnit.SECONDS);
    }
}
